package com.software.cm.managedControllers;

import com.software.cm.spring.model.Employee;
import com.software.cm.spring.service.EmployeeService;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import java.io.Serializable;

/**
 * Created by mcan on 29/11/2014.
 */
@ManagedBean(name= "employeeMB")
@RequestScoped
public class EmployeeManagedBean implements Serializable {

    @ManagedProperty("#{employeeService}")
    private EmployeeService employeeService;

    private Employee employee = new Employee();

    public EmployeeService getEmployeeService() {
        return employeeService;
    }

    public void setEmployeeService(EmployeeService employeeService) {
        this.employeeService = employeeService;
    }

    public Employee getEmployee() {
        return employee;
    }

    public void setEmployee(Employee employee) {
        this.employee = employee;
    }

    public String register()
    {
        employeeService.addEmployee(employee);
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage("The Employee "+this.employee.getEmployeeName()+" Is Registered Successfully"));
        return "";
    }
}
